/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.threadpool;

/**
 *
 * @author Neophron
 */
public class MyThread implements Runnable {

    private boolean isWorking = false;

    private final MyQueue<Runnable> queue;

    MyThread(MyQueue<Runnable> queue) {
        this.queue = queue;
    }

    public boolean isWorking() {
        return isWorking;
    }

    @Override
    public void run() {
        while (true) {
            while (queue.isEmpty()) {
            }
            isWorking = true;
            try {
                Runnable r = queue.poll();
                r.run();
            } finally {
                isWorking = false;
            }
        }
    }
}
